package com.dayuanit.dy15.lesson28.demo2;

public class Test {
    public static void main(String[] args) throws Exception {
        //线程的 join方法

        System.out.println(Thread.currentThread().getName() + " begin");

        //创建一个t1线程
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " run() begin");

                try {
                    Thread.yield();//当前线程主动放弃执行。
                    Thread.sleep(20 * 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName() + " run() end");
            }
        }, "t1");

        t1.start();//启动线程

//        t1.join();//当前线程 要等待t1线程执行结束后，才能继续向下执行
        t1.join(10 * 1000);

        System.out.println(Thread.currentThread().getName() + " end");

    }
}
